package chatroom;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author Gong
 * @Description
 * @dATE 2022/4/20 10:46
 **/
@WebServlet("/s1")
public class S1 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        request.getRequestDispatcher("/s2").forward(request,response);//转发,/代表的是，服务器内的跳转
//        response.sendRedirect(request.getContextPath()+"/chatroom/chatroom.jsp");//重定向，不局限服务器
//        response.sendRedirect("http://www.baidu.com");//重定向到外网
//        response.sendError(407, "Need authentication!!!" );
//        response.setStatus(100);
        ServletContext servletContext = this.getServletContext();
        // 第二种方法
        // ServletContext servletContext2 = this.getServletConfig().getServletContext();
        servletContext.setAttribute("name", "小明");


    }
}